<template>
	<view class="item_wrap">
		<view class="l">
			<u-icon size="30" name="plus-circle" color="#F7EED"
				@click="update_current_amount(detail.id, 'add_step')"></u-icon>
		</view>
		<view class="c" @click="go_detail(detail.id)">
			<view class="target">{{`${detail.target}`}}</view>
			<text class="current_amount">{{`目标：${detail.target_amount}`}}</text>
			<text class="current_amount">{{`当前：${detail.current_amount}`}}</text>
		</view>
		<view class="r">
			<u-icon v-show="detail.current_amount > 1" size="30" name="minus-circle" color="#F7EED"
				@click="update_current_amount(detail.id, 'decrease_step')"></u-icon>
		</view>
	</view>
</template>

<script>
	import {
		request
	} from '@/utils/request.js'

	export default {
		props: {
			detail: {
				type: Object,
				default: () => ({})
			}
		},
		data() {
			return {

			}
		},
		onLoad() {
		},
		methods: {
			async update_current_amount(id, type) {
				const {
					data
				} = await request('POST', '/api/updateCurrentAmount', {
					id,
					type,
				})
				this.$emit('refresh')
			},
			go_detail(id) {
				uni.navigateTo({
					url: `/pages/detail/detail?id=${id}`
				})
			},
		}
	}
</script>

<style>
	.item_wrap {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 10rpx 30rpx;
		background-color: #f1eee8;
		margin: 5rpx 0;
	}

	.c {
		padding: 7rpx 0;
		text-align: center;
	}

	.target {
		font-size: 18px;
		font-weight: 600;
	}

	.current_amount {
		margin: 20rpx 30rpx;
		font-size: 16px;
		color: orange;
	}
</style>
